package com.bykj.taketurns.homefragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bykj.taketurns.R;
import com.bykj.taketurns.homefragment.bean.StageTextBean;

import java.util.List;


public class StageTextGridAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private List<StageTextBean.CharacterListAllBean> list;

    public StageTextGridAdapter(Context context, List<StageTextBean.CharacterListAllBean> characterListAll) {
        mInflater = LayoutInflater.from(context);
        this.context = context;
        this.list = characterListAll;
    }


    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.item_script_rv_text, parent,
                    false);
            viewHolder = new ViewHolder();
            viewHolder.tv_name_script_item =  convertView.findViewById(R.id.tv_name_script_item);
            viewHolder.tv_sum_script_item =  convertView.findViewById(R.id.tv_sum_script_item);
            viewHolder.tv_script_item =  convertView.findViewById(R.id.tv_script_item);
            viewHolder.iv_ranking =  convertView.findViewById(R.id.iv_ranking);

            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_name_script_item.setText(list.get(position).getUnickname());
        viewHolder.tv_sum_script_item.setText(list.get(position).getUhiddenid());
        viewHolder.tv_script_item.setText(list.get(position).getSccontent());

        if (position == 0){
            viewHolder.iv_ranking.setVisibility(View.VISIBLE);
            viewHolder.iv_ranking.setImageResource(R.mipmap.one);
        }else if (position == 1){
            viewHolder.iv_ranking.setVisibility(View.VISIBLE);
            viewHolder.iv_ranking.setImageResource(R.mipmap.two);
        }else if (position == 2){
            viewHolder.iv_ranking.setVisibility(View.VISIBLE);
            viewHolder.iv_ranking.setImageResource(R.mipmap.three);
        }else {
            viewHolder.iv_ranking.setVisibility(View.GONE);
        }

        return convertView;
    }

    private final class ViewHolder
    {
        TextView tv_name_script_item;
        TextView tv_sum_script_item;
        TextView tv_script_item;
        ImageView iv_ranking;

    }

}
